package cn.cvs.servlet.supplier;

import cn.cvs.pojo.Supplier;
import cn.cvs.service.SupplierService;
import cn.cvs.util.SpringUtil;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "SupplierGetListServlet", urlPatterns = "/sys/supplier/simpleList")
public class SupplierGetListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet ( request, response );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding ( "utf-8" );
        response.setContentType ( "text/html;charset=UTF-8" );
        SupplierService supplierService = (SupplierService) SpringUtil.getBean ( "supplierService" );
        List<Supplier> list = supplierService.getList ( );
        PrintWriter writer = response.getWriter ( );
        writer.print ( JSON.toJSONString(list) );
        writer.close ();
    }
}
